package com.atguigu.flink.sql.query;

import org.apache.flink.table.api.EnvironmentSettings;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.TableEnvironment;

import static org.apache.flink.table.api.Expressions.$;
import static org.apache.flink.table.api.Expressions.call;

/**
 * Created by 黄凯 on 2023/6/27 0027 21:24
 *
 * @author 黄凯
 * 永远相信美好的事情总会发生.
 */
public class Flink12_SystemFunction {

    public static void main(String[] args) {

        TableEnvironment tableEnv = TableEnvironment.create(EnvironmentSettings.newInstance().build());
        String readSql =
                " create table t2 (" +
                        " id STRING , " +
                        " vc INT , " +
                        " ts BIGINT " +
                        ") WITH (" +
                        " 'connector' = 'jdbc', " +
                        " 'url' = 'jdbc:mysql://hadoop102:3306/test', " +
                        " 'table-name' = 's2', " +
                        " 'username' = 'root', " +
                        " 'password' = '000000' " +
                        ")";
        tableEnv.executeSql(readSql);

        //使用系统函数
        //SQL
//        tableEnv.sqlQuery("select UPPER(id) , vc , ts from t2").execute().print();

        //API
        Table table = tableEnv.from("t2");
        //table.select($("id").upperCase() , $("vc"), $("ts")).execute().print();
        table.select(call("upper", $("id")), $("vc"), $("ts")).execute().print();


    }

}
